package com.wolf.cx330.view.frag

import android.animation.ObjectAnimator
import android.animation.TypeEvaluator
import android.graphics.Point
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.AccelerateDecelerateInterpolator
import androidx.fragment.app.Fragment
import com.wolf.cx330.R
import kotlinx.android.synthetic.main.frag_point_anim.*

class PointAnimFrag : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View = inflater.inflate(R.layout.frag_point_anim, container, false)

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        ObjectAnimator.ofObject(
            fpaPointView, "point",
            TypeEvaluator<Point> { fraction, startValue, endValue ->
                val x = startValue.x + fraction * (endValue.x - startValue.x)
                val y = startValue.y + fraction * (endValue.y - startValue.y)
                Point(x.toInt(), y.toInt())
            }, Point(100, 100), Point(800, 500)
        ).apply {
            duration = 1000
            interpolator = AccelerateDecelerateInterpolator()
            repeatCount = ObjectAnimator.INFINITE
            repeatMode = ObjectAnimator.REVERSE
            start()
        }
    }
}